<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>预约考试</title>
<%@ include file="/WEB-INF/layouts/comm/datatables.jsp"%>
</head>
<body>
	<div class="mod_header">
		<div class="title">
			<h2 id="h_title">预约考试</h2>
		</div>
	</div>
	<ol class="breadcrumb">
		<li><a href="#">功能设置</a></li>
		<li class="active">预约考试</li>
	</ol>
	<div class="mod_basic">
		<div class="title">
			<h3>预约考试信息</h3>
			<div class="tabs" id="div_item_tabs">
				<a id="tab_1" href="javascript:changeType('ALL','tab_1');"
					class="current">全部信息</a> <a id="tab_2"
					href="javascript:changeType('NOW','tab_2');" class="">可预约的考试</a> <a
					id="tab_3" href="javascript:changeType('LOS','tab_3');">过期的预约考试</a>
			</div>
		</div>

		<div class="content">
			<div class="sub_content_table_tool">
				<div class="sub_header">
					<div class="sub_bar">
						<a href="${ctx}/webCustomer/exam/add" class="btn btn-primary "><i
							class="fa fa-plus"></i> 新建预约考试信息</a> <a
							href="${ctx}/webCustomer/exam/examConfig"
							class="btn btn-primary "><i class="fa fa-cfg"></i> 预约考试设置</a>
					</div>
				</div>
			</div>
			<div class="sub_content_table">
				<table
					class="table table-striped table-bordered table-hover datatable"
					id="datatable">
					<thead>
						<tr>
							<th>标题</th>
							<th>考试日期</th>
							<th>报名开始时间</th>
							<th>考试开放时间</th>
							<th>创建时间</th>
							<th>操作</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
	</div>
	<footer_body> <script id="tpl"
		type="text/x-handlebars-template">
	    {{#each func}}
	    <button type="button" class="btn btn-{{this.type}} btn-sm" onclick="{{this.fn}}">{{this.name}}</button>
	    {{/each}}
	</script> <script>
		var tpl = $("#tpl").html();
		//预编译模板
		var template = Handlebars.compile(tpl);

		base.menu.active('menu_203');

		var table = base.datatable
				.table({
					tableid : '#datatable',
					aoColumns : [ {
						"data" : "title"
					}, {
						"data" : "examTime"
					}, {
						"data" : "resTime"
					}, {
						"data" : "openHours"
					}, {
						"data" : "createTime"
					}, {
						"data" : "id"
					} ],
					columnDefs : [ {
						targets : 5,
						render : function(a, b, c, d) {
							var context = {
								func : [
										{
											"name" : "查看预约报名信息",
											"fn" : " window.location.href='${ctx}/webCustomer/examItem/exam_"
													+ c.id + "'",
											"type" : "danger"
										},
										{
											"name" : "删除",
											"fn" : "del(" + c.id + ",'"
													+ c.title + "')",
											"type" : "default"
										} ]
							};
							var html = template(context);
							return html;
						}
					} ],
					url : "${ctx}/webCustomer/exam/data?rand=" + Math.random()
				});

		var _type = "ALL";
		function changeType(type, tabid) {
			if (_type != type) {
				base.datatable.reloadAjax({
					url : "${ctx}/webCustomer/exam/data?type=" + type
							+ "&rand=" + Math.random()
				});
				_type = type;
				$('.tabs a').removeClass('current');
				$('#' + tabid).addClass('current');
			}
		}

		function del(id, name) {
			base.dialog
					.confirm({
						msg : "是否要删除[" + name + "]的报名信息",
						callback : function(result) {
							if (result) {
								base.ajax
										.get({
											url : '${ctx}/webCustomer/exam/del?id='
													+ id,
											success : function(json) {
												if (json.data == true) {
													base.dialog
															.alert({
																msg : "删除成功",
																callback : function() {
																	base.datatable
																			.reloadAjax({
																				url : "${ctx}/webCustomer/exam/data?rand="
																						+ Math
																								.random()
																			});
																}
															});
												} else {
													base.dialog.alert({
														title : '错误',
														msg : "系统错误"
													});
												}
											}
										});
							}
						}
					});
		}
	</script> </footer_body>
</body>
</html>